perf(qwen4): optimize gated residual kernels and PDL - #1323
Conversation
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 878bd8970c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f39e97c459
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7a7e50557
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 767b9c0e0a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| stream_id = int(torch.cuda.current_stream(device).cuda_stream) | ||
| key = (device_index, stream_id, projection_rows) | ||
| workspace = _PERSISTENT_WORKSPACES.get(key) |
There was a problem hiding this comment.
Isolate persistent workspaces by captured graph
When multiple CUDA graphs are captured on the same stream and later replayed concurrently on different streams, this stream-only key makes every graph capture the same raw and counters pointers. The runtime graph wrapper captures all batch-size variants on one shared capture stream, so concurrent use of those graph executables would let persistent kernels zero and atomically update the same barrier state, potentially corrupting projections or hanging in _grid_barrier; give overlapping graph executions distinct workspace storage rather than keying solely by the capture stream handle.
Useful? React with 👍 / 👎.
Signed-off-by: tuanzhangCS <tuan@lightseek.org>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d66622b074
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| raise ValueError( | ||
| f"{name} must have last dimension {width}, got {tuple(value.shape)}" | ||
| ) | ||
| return value.reshape(-1, width) |
There was a problem hiding this comment.
Preserve last-dimension strides before launching epilogues
When a caller passes a 2-D feature-strided view such as base[:, ::2] with the required logical width, this reshape can preserve its non-unit last-dimension stride. Both _mix_epilogue_kernel and _combine_kernel then address features as ptr + column without receiving a column stride, so the general mix and combine paths read incorrect elements; the previous runtime implementations explicitly made these operands contiguous. Make the flattened operands contiguous when their last-dimension stride is not one, or pass that stride to the kernels.
Useful? React with 👍 / 👎.
Summary
Performance
Compared with baseline 63f4585 on an NVIDIA B200 using BF16, PDL enabled, and CUDA Graph replay. The benchmark covers the full runtime grouped RMSNorm + gated-residual mix + combine chain; values are medians from five interleaved runs.
The CUDA Graph geometric-mean improvement across the tested shapes is 16.57%, with no regression in any tested shape. The persistent Triton path provides the largest gain through 16 tokens; the general path remains 4.70%-5.43% faster above that range. CuTeDSL remains available for explicit tuning rather than default dispatch.
Test Plan
The focused Qwen4 test module is not collectable in the current local environment because its installed tuning dependency does not yet accept the tensor_initializers argument; the changed paths are covered by the focused runtime and kernel suites above.